package com.ilovepostcard.view;

import com.ilovepostcard.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class PostcardTabItem extends RelativeLayout {

    private ImageView mHighlightView;
    
    public PostcardTabItem(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        inflate(attrs);
    }

    public PostcardTabItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate(attrs);
    }

    public PostcardTabItem(Context context) {
        super(context);
        inflate(null);
    }
    
    public void setHighlight(boolean h) {
        mHighlightView.setImageResource(h ? R.drawable.discover_topbar_scrollbar : 0);
    }
    
    private void inflate(AttributeSet attrs) {
        View view = View.inflate(getContext(), R.layout.tabbar_item, this);
        mHighlightView = (ImageView) view.findViewById(R.id.tabbar_highlight);
        if (attrs != null) {
            TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.PostcardTab);
            TextView tv = (TextView) view.findViewById(R.id.tabbar_text);
            tv.setText(ta.getString(R.styleable.PostcardTab_text));
            boolean highlight = ta.getBoolean(R.styleable.PostcardTab_highlight, false);
            setHighlight(highlight);
        }
        
    }

}
